#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>

int main(int argc ,char *argv[])
{

	pid_t id = fork();

	if(id<0)
	{
		perror("fork");
		exit(EXIT_FAILURE);
	}
	else if(id == 0)
	{
		//子进程
		char *program = "ls";
		char *myargv[] = {"-a","-l",NULL};
		execvp(program ,myargv);
	}
	else
	{
		//父进程
		printf("这是父进程：pid = %d, 等待子进程：pid = %d\n",getpid(),id);
		int status;
		waitpid(id ,&status ,0);

		printf("子进程已完成，父进程等待成功退出!\n");
	}	

	return 0;
}
